<template>
  <div class="app-container ">
    <el-form ref="form" size="mini" :model="form" :rules="rules" label-width="180px">
      <el-tabs v-model="activeName">
        <el-tab-pane style="padding-top:10px" :label="lang.technical+'设置'" :name="lang.technical+'设置'">
          <el-row>
            <el-col :span="24">
              <el-form-item :label="lang.technical+'抢单'">
                <el-radio-group v-model="form.is_pickuporder">
                  <el-radio label="0">关闭</el-radio>
                  <el-radio label="1">开启</el-radio>
                </el-radio-group>
                <div class="help-block">开启后，{{lang.technical}}可以手机端抢单</div>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item :label="lang.technical+'查看已接订单的电话号'">
                <el-radio-group v-model="form.close_ordertel">
                  <el-radio label="0">可见</el-radio>
                  <el-radio label="1">隐藏</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item :label="lang.technical+'有订单没完不能接单'">
                <el-radio-group v-model="form.is_multipleorder">
                  <el-radio label="0">关闭</el-radio>
                  <el-radio label="1">开启</el-radio>
                </el-radio-group>
                <div class="help-block">开启后，{{lang.technical}}有订单没完不能接单</div>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item label="默认返佣比例">
                <el-input v-model="form.return_percent" style="width:500px;" auto-complete="off" clearable
                  placeholder="请输入默认佣金比例">
                  <template slot="append">%</template>
                </el-input>
                <div class="help-block">
                  如果{{lang.technical}}没有等级，佣金按这里的比例结算。<br>
                  注：如果商家/服务点的{{lang.technical}}，返佣比例需要减去商家的返佣比例。<br>
                  比如：{{lang.technical}}返佣是60%,商家返佣10%,最终商家的{{lang.technical}}返佣50%</div>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item label="最少提现额度">
                <el-input v-model="form.min_money" style="width:500px;" auto-complete="off" clearable
                  placeholder="请输入最少提现额度">
                  <template slot="append">元</template>
                </el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item label="每日提现上限">
                <el-input v-model="form.cash_max_day" style="width:500px;" auto-complete="off" clearable
                  placeholder="请输入每日提现上限">
                  <template slot="append">元</template>
                </el-input>
                <div class="help-block">0元表示不限制每日提现金额</div>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item label="提现手续费">
                <div style="margin-bottom: 8px;" v-for="(item, index) in form.cash_service_charge_list" :key="index">
                    <el-radio-group v-model="item.calculate_method">
                      <el-radio label="0">百分比</el-radio>
                      <el-radio label="1">固定金额</el-radio>
                    </el-radio-group>
                    <el-input v-model="item.title" style="width:180px;margin-left: 10px;margin-right: 3px;" auto-complete="off" clearable
                      placeholder="文字说明">
                    </el-input>
                    <el-input v-model="item.days" style="width:180px;margin-left: 10px;margin-right: 3px;" auto-complete="off" clearable
                      placeholder="请输入到帐天数">
                      <template slot="append">天到帐</template>
                    </el-input>
                    <el-input v-model="item.price" style="width:180px;margin-left: 10px;margin-right: 3px;" auto-complete="off" clearable
                      placeholder="提现手续费">
                      <template v-if="item.calculate_method=='0'" slot="append">%</template>
                      <template v-if="item.calculate_method=='1'" slot="append">元</template>
                    </el-input>
                    <el-button @click="addItem()">+</el-button>
                    <el-button @click="deleteItem(index)">–</el-button>

                </div>
                <div class="help-block">0表示不设置提现手续费
                  <span class="text-danger">提现手续费额外从提现中扣除</span><br>
                  例如：<span class="text-danger">10%</span>的提现手续费：<br>
                  提现<span class="text-danger">100</span>元，扣除手续费<span class="text-danger">10</span>元，
                  实际到手<span class="text-danger">90</span>元
                </div>
              </el-form-item>
            </el-col>
          </el-row>
        </el-tab-pane>
      </el-tabs>
      <el-form-item>
        <el-button size="mini" type="primary" @click="submit">保存设置</el-button>
      </el-form-item>
    </el-form>

  </div>
</template>
<script>
  export default {
    name: 'Configtechnical',
    components: {},
    data() {
      return {
        lang: {},
        form: {},
        loading: false,
        activeName: '',
        rules: {}
      }
    },
    mounted() {
      this.$api.post('/Lang/getlang').then(res => {
        this.lang = res.data
        this.activeName = this.lang.technical +"设置";
      })
      this.$api.post('/config/getInfo', {
        mo: 'technical'
      }).then(res => {
        this.form = JSON.stringify(res.data) == '[]' ? {} : res.data
        this.setDefaultVal('keyword')
      })
    },
    methods: {
      submit() {
        this.$refs['form'].validate(valid => {
          if (valid) {
            this.loading = true
            this.$api.post('/config/update', this.form).then(res => {
              this.$message({
                message: '操作成功',
                type: 'success'
              })
            }).catch(() => {
              this.loading = false
            })
          }
        })
      },
      setDefaultVal(key) {
        if (this.form[key] == null || this.form[key] == '') {
          this.form[key] = []
        }
      },
      addItem() {
        let that = this;
        that.form.cash_service_charge_list.push({
          days: "",
          calculate_method: '0',
          price: ""
        });
      },
      deleteItem(i) {
        if (this.form.cash_service_charge_list.length <= 1) {
          return false;
        }
        this.form.cash_service_charge_list.splice(i, 1);
      }
    }
  }
</script>
